package database;

import java.util.LinkedList;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import car.manager.DataBaseConnection;
import car.manager.UserProfile;

public class DataBaseUserProfile extends DataBaseConnection{

	
	
	
	
	
	
	
	public DataBaseUserProfile(Context context) {
		super(context);

	}

	private LinkedList<UserProfile> loadProfiles() {

		LinkedList<UserProfile> upList = new LinkedList<UserProfile>();

		//should this be on DatabaseConnection?
		SQLiteDatabase database = null;
		try{
		database = this.getReadableDatabase();
		Cursor cursor = database.query(PROFILE_TABLE, null,
				null, null, null, null, null, null);

		//if Profile table is not empty
		if (cursor.moveToFirst()) {
			do {
				upList.add(
						new UserProfile(cursor.getInt(cursor.getColumnIndex(PROFILE_ID)),
								cursor.getString(cursor.getColumnIndex(PROFILE_NAME)),
								cursor.getFloat(cursor.getColumnIndex(PROFILE_CREDIT)),
								cursor.getInt(cursor.getColumnIndex(PROFILE_EXPERIENCE)))
						);

			} while (cursor.moveToNext());


		}
		//this may return an empty list, careful
		return upList;
		
		}finally{
			//will this be read despite of return?
			database.close();
		}


	}
}
